<template>
    <div class="sub-layout user-edit-content">
        <div class="sub-sidebar">
            <div class="search-bar">
                <div class="search-box">
                    <el-select v-model="search.value" placeholder="搜索用户..." filterable remote :remote-method="searchMethod" :loading="search.loading"
                        @change="searchChange">
                        <el-option v-for="item in search.list" :key="item.value" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                    <i class="icon i-search"></i>
                </div>
                <permission class="add" permission-key="user:addDept">
                    <a @click="showEditLayer(0)">
                        <i class="icon i-plus"></i>
                    </a>
                </permission>
            </div>
            <div class="side-nav">
                <el-tree node-key="id" :props="deptDefaultProps" :data="deptList" @node-click="nodeClick"></el-tree>
            </div>
        </div>
        <div class="sub-main">
            <div class="content">
                <div class="section section-panel">
                    <div class="panel-title">
                        <span class="title">{{title}}</span>
                    </div>
                    <div class="panel-content">
                        <div class="form-box">
                            <el-form inline :ref="form.ref" :rules="form.rules" :model="userDetail" @submit.prevent>
                                <el-form-item label="用户姓名" prop="name">
                                    <el-select v-if="!userId" v-model="userDetail.name" placeholder="搜索用户姓名" filterable remote allow-create :remote-method="searchUserMethod"
                                        :loading="form.loading" @change="selectUser">
                                        <el-option v-for="item in form.searchList" :key="item.id" :label="item.userName" :value="item.id"></el-option>
                                    </el-select>
                                    <el-input v-else type="text" v-model="userDetail.name" placeholder="请输入用户姓名"></el-input>
                                </el-form-item>
                                <el-form-item label="邮箱地址" prop="email">
                                    <el-input type="text" v-model="userDetail.email"></el-input>
                                </el-form-item>
                                <el-form-item label="所属公司" prop="companyName">
                                    <el-input type="text" v-model="userDetail.companyName"></el-input>
                                </el-form-item>
                                <el-form-item label="所属部门" prop="departmentName">
                                    <el-input type="text" v-model="userDetail.departmentName"></el-input>
                                </el-form-item>
                                <el-form-item label="职位" prop="position">
                                    <el-input type="text" v-model="userDetail.position"></el-input>
                                </el-form-item>
                                <el-form-item label="身份证号" prop="identity">
                                    <el-input type="text" v-model="userDetail.identity"></el-input>
                                </el-form-item>
                                <el-form-item label="手机号" prop="phone">
                                    <el-input type="text" v-model="userDetail.phone"></el-input>
                                </el-form-item>
                                <el-form-item label="登录密码" prop="password">
                                    <el-input type="text" v-model="userDetail.password"></el-input>
                                </el-form-item>
                                <div class="el-form-item is-required form-block">
                                    <label class="el-form-item__label">角色</label>
                                    <div class="el-form-item__content">
                                        <div class="input-box">
                                            <el-checkbox-group v-model="form.selectedRoles">
                                                <el-checkbox v-for="item in roleList" :key="item.id" :label="item.name"></el-checkbox>
                                            </el-checkbox-group>
                                        </div>
                                    </div>
                                </div>
                                <div class="el-form-item is-required form-block">
                                    <label class="el-form-item__label">所监察产品类型</label>
                                    <div class="el-form-item__content">
                                        <div class="input-box">
                                            <el-checkbox-group v-model="form.selectedProducts">
                                                <el-checkbox v-for="item in dicts.productType" :key="item.id" :label="item.name"></el-checkbox>
                                            </el-checkbox-group>
                                        </div>
                                    </div>
                                </div>
                                <div class="el-form-item form-block">
                                    <label class="el-form-item__label">负责内容</label>
                                    <div class="el-form-item__content">
                                        <div class="input-box">
                                            <div class="transfer">
                                                <div class="transfer-title">
                                                    <span>营业部</span>
                                                </div>
                                                <div class="transfer-content">
                                                    <div class="tag">
                                                        <div class="tag-item" v-for="(item,index) in form.selectedOrgs.ids">
                                                            <span>{{form.selectedOrgs.names[index]}}</span>
                                                            <i class="icon i-error" @click="closeOrg(index)"></i>
                                                        </div>
                                                    </div>
                                                    <!-- <el-tree ref="treeDept" lazy show-checkbox check-strictly node-key="deptCode" :props="form.defaultProps" :default-checked-keys="form.defaultCheckedId"
                                                        :load="loadOrgList" @check-change="orgCheckChange">
                                                    </el-tree> -->
                                                    <el-cascader placeholder="请选择营业部" :options="form.deptJcList" @active-item-change="getDeptJc" @change="deptJcChange" :props="form.defaultProps"></el-cascader>
                                                </div>
                                            </div>
                                            <a class="clear" @click="clearOrg">清空</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="el-form-item form-block">
                                    <label class="el-form-item__label">备注信息</label>
                                    <div class="el-form-item__content">
                                        <el-input type="textarea" v-model="userDetail.remark" class="input-textarea" placeholder="请输入备注信息"></el-input>
                                    </div>
                                </div>
                            </el-form>
                            <div class="form-btn">
                                <permission permission-key="user:addUser">
                                    <button @click.prevent="sumbitForm">保存</button>
                                </permission>
                                <button class="btn-cancel" @click="goBack">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 编辑layer -->
        <layer :data="editLayerData" @on-cancel="closeEditLayer" @on-ok="editLayerConfirm">
            <div class="el-form">
                <div class="el-form-item is-required" :class="{'is-error':editLayerData.error}">
                    <label class="el-form-item__label" style="width: 100px;">类别名称</label>
                    <div class="el-form-item__content" style="margin-left: 112px;">
                        <div class="el-input">
                            <input autocomplete="off" type="text" validateevent="true" class="el-input__inner" placeholder="请输入类别名称" v-model="editLayerData.name"
                                @blur="layerInputBlur">
                        </div>
                        <div class="el-form-item__error" v-if="editLayerData.error">请输入类别名称</div>
                    </div>
                </div>
            </div>
        </layer>
    </div>
</template>
<script>
    import userEditMixin from './userEdit'
    export default {
        name: 'userEdit',
        mixins: [userEditMixin]
    }
</script>